﻿using BTS.Common;
using BTS.Helpers;
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static BTS.Models.LoginWindowModel;

namespace BTS.Common
{
    [Serializable]
    public partial class SystemConfig:ObservableObject
    {

        #region Singleton

        private static SystemConfig _instance = new SystemConfig();
        public SystemConfig()
        {
        }
        public static SystemConfig Ins
        {
            set { _instance = value; }
            get { return _instance; }
        }
        #endregion

        public void LoadSystemConfig()
        {
            Ins = SerializeHelper.Deserialize<SystemConfig>(FilePaths.SystemConfig, true);
            if (Ins == null)
            {
                Ins = new SystemConfig();
                SaveSystemConfig();
            }
        }

        private static object Lock_SaveSystemConfig = new object();
        public void SaveSystemConfig()
        {
            lock (Lock_SaveSystemConfig)
            {
                SerializeHelper.SerializeAndSaveFile(SystemConfig.Ins, FilePaths.SystemConfig, true);
            }
        }



        [ObservableProperty]
        private string _lang ="zh";

        [ObservableProperty]
        private LogLevel logLevel=LogLevel.Debug;

        [ObservableProperty]
        private  string? company = "欣旺达电子（深圳）有限公司";

        [ObservableProperty]
        private  User userInfo= new User() { AccountType = eUserTypes.本地账户, AccountAuth = eUserAuths.操作员};
     
        [ObservableProperty]
        private string? softwareIcoPath;

    }
}
